/**   
* @Title: ValidationFingerPrint.java 
* @Package ferly.finger 
* @Description: 用一句话描述该文件做什么 
* Copyright: Copyright (c) 2014 
* Company:wolf-yan team by iss
* @author: as   
* @date: 2014年7月28日 下午3:52:51 
* @version: V1.0
* update Release(文件修正记录)
* <pre>
* author--updateDate--description----------------------Flag————
* wolf-yan    2014-5-1    测试codesyle                      #wolf-yan001
*
*
*
* </pre>
*
*/
package com.kerrykidz.common.finger;

import java.io.IOException;

import com.sun.jna.Library;
import com.sun.jna.Native;

/** 
 * @ClassName: ValidationFingerPrint 
 * @description: 大致描述该类的用途，内容简短易懂 
 * @author: as 
 * @date: 2014年7月28日 下午3:52:51 
 * @version: V1.0
 *
 */
public class ValidationFingerPrint {
	public static String webPath = getRealPath();

	//定义接口CLibrary，继承自com.sun.jna.Library
    public interface CLibrary extends Library
    {
    	//32位系统
    	//String path = webPath + "WEB-INF/classes/jnidll/fLAlgJni/FL727api_nx.dll";
    	
    	//64位系统
    	String path = webPath + "WEB-INF/classes/finger/FL727api_nx_x64.dll";
    	
    	CLibrary library = (CLibrary)Native.loadLibrary(path, CLibrary.class);

        int FL_AlgUserMatch_B64(byte[] data, byte[] data2, char level, int[] score);
        
    }
    
    /**
	 * @return 得到工程当前目录
	 */
	public static String getRealPath() {
		String path = ValidationFingerPrint.class.getResource("").getPath();
		path = path.substring(1, path.indexOf("WEB-INF/"));
		return path;
	}
	
	/**
	 * 指纹比对函数
	 * @param fingerData1
	 * @param fingerData2
	 * @return 
	 */
	public synchronized static int userMatch(String fingerData1, String fingerData2){
		CLibrary library = CLibrary.library;
		char level = 3;
		int[] score = new int[1];
		int result = library.FL_AlgUserMatch_B64(fingerData1.getBytes(), fingerData2.getBytes(), level, score);
		return result;
	} 
	
	public static void main(String[] args) throws IOException {
		String fl1 = "AwFhFQAAwB6ADgAGAAIAAgACAAAAAAAAAAAAAAAAAAAAAAAAAACAAgAAAAAAAAAAAAAAAAAAAAA4lVgeL5yXfkCjQ75eKFt+EzESvhy0lN5Iwpk+SIcZP0sYQx9bmllfSCAY/1sjhL9Np5ofRasYn042hF9gu1rfV0Aa3xQ1av0+w1m4P0DDeXE42u4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";
		String fl2 = "AwFiFQAAwB6ADgAGAAIAAgACAAAAAAAAAAAAAAAAAAAAAAAAAACAAgAAAAAAAAAAAAAAAAAAAAA4FRfeL5xXPkCjQ75eKFt+EzESvhy0lN5Iwpk+SAcZX0sYQx9bmllfSCAY/1sjRP9Np5ofRasYv042hH9gu1rfV0Aa3xQ1av0+w1m4P0DDeXE42w4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";
		int x = userMatch(fl1, fl2);
		if(x==0){
			System.out.println("比对成功");
		}else{
			System.out.println("比对失败");
		}
	}
}
